package com.jeedcp.shiro.sys.controller;


import com.jeedcp.core.common.JsonResult;
import com.jeedcp.core.controller.BaseController;
import com.jeedcp.core.util.ConvertUtils;
import com.jeedcp.shiro.jwt.JwtUtil;
import com.jeedcp.shiro.sys.dto.MenuDto;
import com.jeedcp.shiro.sys.entity.Menu;
import com.jeedcp.shiro.sys.entity.User;
import com.jeedcp.shiro.sys.service.IMenuService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 菜单权限表 前端控制器
 * </p>
 *
 * @author caochaofeng
 * @since 2019-08-15
 */
@Controller
@RequestMapping("/sys/menu")
public class MenuController extends BaseController<IMenuService,Menu,MenuDto> {

    /**
     * 获取所有菜单
     */
    @GetMapping("/all")
    public JsonResult<HashMap<String, Object>> all() {
        User user = JwtUtil.getCurrentUser();
        List<Menu> menuList = baseService.getUserMenus(user);
        List<MenuDto> menuDtoList = ConvertUtils.sourceToTarget(menuList, getDClass());
        Set<String> permissions = baseService.getUserPermissionsList(user);
        HashMap map = new  HashMap<String, Object>();
        map.put("menuList", menuDtoList);
        map.put("permissions", permissions);
        return new JsonResult<HashMap<String, Object>>().ok(map);
    }

}
